/*
 * Copyright (c) 2015 www.smarthome.com All rights reserved. 本软件源代码版权归----所有,未经许可不得任意复制与传播.
 */
package com.smarthome.base.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.smarthome.base.dao.ShPropertyCompanyDao;
import com.smarthome.base.dao.base.BaseDao;
import com.smarthome.base.service.ShPropertyCompanyService;
import com.smarthome.base.service.base.BaseServiceImpl;
import com.smarthome.domain.bean.ShPropertyCompany;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;

/**
 * ShPropertyCompanyService 实现类
 * @author KongXiangyu
 * @since 2015-09-07
 */
@Service("shPropertyCompanyService")
public class ShPropertyCompanyServiceImpl extends BaseServiceImpl<ShPropertyCompany, Long> implements ShPropertyCompanyService {

    @Resource
    private ShPropertyCompanyDao shPropertyCompanyDao;

    public BaseDao<ShPropertyCompany, Long> getDao() {
        return shPropertyCompanyDao;
    }

	@Override
	public DataGrid quetyDataGrid(ShPropertyCompany company, PageHelper page) {
		
		if(null == company) company = new ShPropertyCompany();
		DataGrid grid = new DataGrid();
		
		if(!StringUtils.isBlank(page.getOrder())){
			company.setOrderFieldType(page.getOrder());
		}
		if(!StringUtils.isBlank(page.getSort())){
			company.setOrderField(page.getSort());
		}
		
		if(!StringUtils.isBlank(company.getName())){
			company.addQueryData("name",company.getName());
		}
		
		
	   int startIndex = (page.getPage() - 1) * page.getRows();
	   int endIndex = page.getPage() * page.getRows();
	   Integer count = shPropertyCompanyDao.selectEntryListCount(company);
	   grid.setTotal(count+ 0l);
		
	   if (grid.getTotal() > 0 && grid.getTotal() > startIndex) {
		      company.setStartIndex(startIndex);
		      company.setEndIndex(endIndex);
	    	  List<ShPropertyCompany> rows =  shPropertyCompanyDao.queryShResidences(company);
	    	  grid.setRows(rows);
	    }
		
		return grid;
	}

	@Override
	public List<ShPropertyCompany> queryList(ShPropertyCompany queryCompany) {
		return shPropertyCompanyDao.queryShResidences(queryCompany);
	}

}